package com.sservice.service.service.impl;

import com.sservice.model.dao.IGoodsDao;
import com.sservice.model.entity.Goods;
import com.sservice.urp.entity.User;
import com.sservice.model.vo.GoodsVo;
import com.sservice.service.service.IGoodsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GoodsServiceImpl implements IGoodsService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IGoodsDao dataDao;

    @Override
    public List<Goods> queryByPage(GoodsVo user) {
        return dataDao.queryByPage(user);
    }


    @Override
    public int deleteByPrimaryKey(Integer id) {
        return dataDao.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Goods record) {
        return dataDao.insert(record);
    }

    @Override
    public int insertSelective(Goods record) {
        return dataDao.insertSelective(record);
    }

    @Override
    public Goods selectByPrimaryKey(Integer id) {
        return dataDao.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Goods record) {
        return dataDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<Goods> queryGoodsCategory(GoodsVo user) {
        return dataDao.queryGoodsCategory(user);
    }

    @Override
    public List<Goods> selectByIds(List<String> ids) {
        return dataDao.selectByIds(ids);
    }

    @Override
    public List<User> queryGoodsQQ() {
        String operateIds = dataDao.queryGoodsOperator();
        List<String> operateIds_ = java.util.Arrays.asList(operateIds.split(","));
        return dataDao.queryGoodsOperatorQQ(operateIds_);
    }

    @Override
    public int isOperator(Goods user) {
        return dataDao.isOperator(user);
    }


    @Override
    public int queryCount(GoodsVo user) {
        return dataDao.queryCount(user);
    }

    @Override
    public List<String> judgeOperator(int userId) {
        List<String> lstr = new ArrayList<String>();
        Goods g = new Goods();
        g.setOperatorId(String.valueOf(userId));
        List<Goods> list = dataDao.queryFindInSet(g);
        if (list.size() == 0) {
            return lstr;
        }

        for (Goods item : list) {
            if (("," + item.getOperatorId() + ",").indexOf("," + userId + ",") > -1) {
                lstr.add(String.valueOf(item.getId()));
            }
        }
        return lstr;
    }
}
